package wechat.app.test

import org.junit.Ignore
import org.junit.Test
import wechat.app.WXCorpAppFactory
import wechat.app.util.PropertyReader
import wechat.app.corp.domain.EngineerNotificationCorpWeChat

class MessageTest {
	private static String CALLBACK_SERVER_URL = "http://58.247.87.218:8090"
	private static String MOBILD_CALLBACK_SERVER_URL = "http://mobileangularui.com/demo"
	String callbackurl
	
	
	@Test
	@Ignore
	def void sendNotificationTest(){
		val ins = EngineerNotificationCorpWeChat.ins=>[
			app = 	WXCorpAppFactory::getDefaultCorpApp		
		]
		ins.sendNormalNotification(newArrayList('enchanter-s'),'test','test', '1111')
	}
	
	@Test
	@Ignore
	def void configTest(){
		val propertyReader = new PropertyReader();
		println('PropertyReader::corpId======='+ propertyReader.corpId)
		println('PropertyReader::SECRET======='+ propertyReader.SECRET)
		println('PropertyReader::AGENTID======='+ propertyReader.AGENTID)
		WXCorpAppFactory::getDefaultCorpApp=>[
			createNews()=>[
				callbackurl = generateUrl("redirect","enchanter-s","rock","11111", "测试任务", "测试任务描述")
				withItem('新消息')=>[
					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
					url= callbackurl
				]
				withItem('任务名称:测试任务\n\r任务描述:测试任务描述')=>[
					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
					url= callbackurl
				]
				send2Users(newArrayList('enchanter-s'))
			]
		]
	}
//	@Test
//	@Ignore
//	def void dslWebPageTest(){
//		
//		WXCorpAppFactory::customerApp=>[
//			createNews()=>[
//				callbackurl = generateUrl("redirect","rockweixinid","rock","11111", "测试任务", "测试任务描述")
//				withItem('新消息')=>[
//					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
//					url= callbackurl
//				]
//				withItem('任务名称:测试任务\n\r任务描述:测试任务描述')=>[
//					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
//					url= callbackurl
//				]
//				send2Users(newArrayList('@all'))
//			]
//		]
//	}
	
	@Test
	@Ignore
	def void dslSendScheduledTest(){
//		ScheduledTaskNotify::sendMsg("rock20110501","test","test","test")
	}
	
	
	//  服务号
	@Test
//	@Ignore
	def void dslSendMessageTest(){
		WXCorpAppFactory::getDefaultCorpApp=>[
			createNews()=>[
				withItem('Test新消息')=>[
//					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
					url= "www.baidu.com"
				]
//				withItem('Test任务名称:\n同意回复“1”， 不同意回复“2”')=>[
////					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
////					url= generateUrl("","","11111", "测试任务", "测试任务描述")
//					url= "www.gitee.com"
//				]
//				send2Users(newArrayList('rock20110501','enchanter-s'))
				send2Users(newArrayList('enchanter-s'))
			]
		]
	}
	@Test
	@Ignore
	def void dslSendMessageDirect3MobildUITest(){
		WXCorpAppFactory::getDefaultCorpApp=>[
			createNews()=>[
				withItem('新消息')=>[
//					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
//					url= generateUrl("","","11111", "测试任务", "测试任务描述")
					url= "www.baidu.com"
				]
//				withItem('任务名称:测试任务\n\r任务描述:测试任务描述')=>[
//					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
//					url= MOBILD_CALLBACK_SERVER_URL
//				]
//				send2Users(newArrayList('ztiange-'))
				send2Users(newArrayList('enchanter-s'))
			]
		]
	}
	@Test
	@Ignore
	def void dslUploadTmpFileTest(){
		WXCorpAppFactory::getDefaultCorpApp=>[
			uploadTmpFile("sample.jpg")=>[
			println("\nmedia_id is "+media_id)	
			]
		]
	}
	@Test
	@Ignore
	def void dslSendMpNewsTest(){
		WXCorpAppFactory::getDefaultCorpApp=>[
			createMPNews()=>[
				withItem('新消息')=>[
					thumb_media_id = "1lbyj8sNRzr-Y4g9yLR_yg05jCum73B3QJiSSa3jPpDygbs03JrdOuscuVxeuT-QMNZLIZLZTi5-p3AN1Ngnb2A"
					content ="test"
				]
				send2Users(newArrayList('enchanter-s'))
			]
		]
	}
		
	@Test
	@Ignore
	def void sendNewAssignmentEventTest () {
		WXCorpAppFactory::getDefaultCorpApp=>[
			createNews()=>[
				withItem('新任务')=>[
//					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
					url= "http://210.22.183.30:8090/assignmentdetail?assignmentId=1" + "&state=newtask"
				]
				withItem('任务名称：测试任务' + '\n计划开始时间：'+ '2017-06-05 15:05' + '\n计划结束时间：2017-06-06 18:00')=>[
//					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
					url= "http://210.22.183.30:8090/assignmentdetail?assignmentId=1" + "&state=newtask"
				]
				send2Users(newArrayList('enchanter-s'))
			]
		]
	}
	
	@Test
	@Ignore
	def void sendAssignmentAcceptEventTest () {
		WXCorpAppFactory::getDefaultCorpApp=>[
			createNews()=>[
				withItem('任务还未被接受')=>[
//					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
//					url= "http://210.22.183.30:8090/assignmentdetail?assignmentId=" + assignmentId + "&state=newtask"
				]
				withItem('任务名称：测试任务' + '\n工程师：Lynn' + '\n计划开始时间：'+ '2017-06-05 15:05' + '\n计划结束时间：2017-06-06 18:00')=>[
//					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
//					url= generateUrl("","","11111", "测试任务", "测试任务描述")
				]
				send2Users(newArrayList('enchanter-s'))
			]
		]
	}
	
	
	def generateUrl(String who, String id, String task_id,String project_name, String task_desc) {
			 CALLBACK_SERVER_URL+"/"+"taskdetails"+"?who="+who +"&assigneeid="+id
				+"&taskid="+task_id
				+"&projectname="+project_name
				+"&taskdesc="+task_desc
	}
	def generateUrl(String request,String who, String id, String task_id,String project_name, String task_desc) {
			 CALLBACK_SERVER_URL+"/"+request+"?who="+who +"&assigneeid="+id
				+"&taskid="+task_id
				+"&projectname="+project_name
				+"&taskdesc="+task_desc
	}
}
